-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[llvm-profgen] Set FirstLoadableAddress only once #151257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-pgo Author: Wei Wang (apolloww) ChangesThe address of the first loadable segment can be zero, so Full diff: https://github.com/llvm/llvm-project/pull/151257.diff 1 Files Affected:
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 0588cb48b2af6..8bc7e7b3b0061 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -199,7 +199,7 @@ class ProfiledBinary {
// The runtime base address that the first executable segment is loaded at.
uint64_t BaseAddress = 0;
// The runtime base address that the first loadabe segment is loaded at.
- uint64_t FirstLoadableAddress = 0;
+ std::optional<uint64_t> FirstLoadableAddress;
// The preferred load address of each executable segment.
std::vector<uint64_t> PreferredTextSegmentAddresses;
// The file offset of each executable segment.
@@ -381,7 +381,10 @@ class ProfiledBinary {
return PreferredTextSegmentAddresses[0];
}
// Return the preferred load address for the first loadable segment.
- uint64_t getFirstLoadableAddress() const { return FirstLoadableAddress; }
+ uint64_t getFirstLoadableAddress() const {
+ assert(FirstLoadableAddress && "FirstLoadableAddress must be set.");
+ return *FirstLoadableAddress;
+ }
// Return the file offset for the first executable segment.
uint64_t getTextSegmentOffset() const { return TextSegmentOffsets[0]; }
const std::vector<uint64_t> &getPreferredTextSegmentAddresses() const {
|
|
I think the convention is to leave the address zero unmapped (ie. at least the first page) so that null pointer dereferences cause segmentation faults. Can you describe the situation where you have seen this behaviour? |
c389225 to
6b8ca0f
Compare
I saw The binary has first |
The address of the first loadable segment can be zero, so
FirstLoadableAddressmay actually point to the second loadable segment. Use an optional instead.